﻿// TestTraceListener.cs
//
// Copyright 2008 by Burt Harris
// Licensed under the Microsoft Public License (Ms-PL)
// See: http://www.codeplex.com/yaml/license
//

using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace YaTools.Yaml.UnitTests
{
    [TestClass]
    public class TestTraceListener : TraceListener
    {
        private static TraceListener _default;

        [AssemblyInitialize]
        public static void AssemblyInitialize(TestContext context)
        {
            _default = Trace.Listeners["Default"];
            Trace.Listeners.Remove(_default);
            Trace.Listeners.Add(new TestTraceListener());
        }

        public override void Fail(string message)
        {
            if (Debugger.IsAttached)
                Debugger.Break();
            throw new AssertFailedException("Trace/Debug failure: " + message);
        }

        public override void Fail(string message, string detailMessage)
        {
            Fail(message);
        }

        public override void Write(string message)
        {
            _default.Write(message);
        }

        public override void WriteLine(string message)
        {
            _default.WriteLine(message);
        }
    }
}